package com.pat.web.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.pat.common.Constants;
import com.pat.web.ApiResponse;
import com.pat.web.model.NoteRecord;
import com.pat.web.model.NoteTags;
import com.pat.web.model.Pet;
import com.pat.web.model.PetCategory;
import com.pat.web.model.PetNote;
import com.pat.web.model.RecordDetails;
import com.pat.web.model.RecordList;
import com.pat.web.model.Warning;
import com.pat.web.services.RecordService;

public class RecordController extends Controller {

	private static final int PAGESIZE = 20;

	private void setAbnormal(NoteRecord noteRecord) {
		// 检查记录是否是异常信息
		// 查找异常警示
		List<Warning> warnings = Warning.dao.find("SELECT * FROM warning WHERE project_id = ? OR project_id IS NULL",
				noteRecord.getProjectId());
		// 获取宠物id
		PetNote petNote = PetNote.dao.findFirst("select * from pet_note where note_id = ?", noteRecord.getNoteId());
		// 获取宠物
		Pet pet = Pet.dao.findFirst("select * from pet where id = ?", petNote.getPetId());
		// 获取宠物分类
		List<PetCategory> petCategories = PetCategory.dao.find(
				"select * from pet_category where id = ? union all "
						+ "select * from pet_category where id = (select parent_id from pet_category where id = ?)",
				pet.getPetCategoryId(), pet.getPetCategoryId());

		noteRecord.setAbnormal(0);
		noteRecord.setAbnormalInfo("");
		if (warnings != null) {
			for (Warning warning : warnings) {
				// 判断异常警示信息是否区分宠物类型
				if (warning.getPetCategoryId() == null) {
					setAbnormalInfo(warning, noteRecord);
				} else { // 区分宠物类别，判断是否与当前宠物是同类别，或当前异常警示信息作用于父节点
					// 判断警示信息宠物类别是否包含手帐宠物类别
					if (petCategories != null) {
						for (PetCategory petCategory : petCategories) {
							// 如果类别相同，则判断是备注信息是否包含异常信息
							if (petCategory.getId().equals(warning.getPetCategoryId())
									|| petCategory.getParentId().equals(warning.getPetCategoryId())) {
								setAbnormalInfo(warning, noteRecord);
							}
						}
					}
				}
			}
		}
	}

	private void setAbnormalInfo(Warning warning, NoteRecord noteRecord) {
		// 判断异常警示是备注警示还是上下限警示
		if (StringUtils.isNotBlank(warning.getRemark())) {
			if (NumberUtils.isNumber(warning.getRemark())) { // 如果异常警示为数字，则判断用户手帐记录数量与异常数量是否相等，相等则异常
				double remark = NumberUtils.toDouble(warning.getRemark());
				if (new BigDecimal(remark).compareTo(noteRecord.getAmount()) == 0) {
					noteRecord.setAbnormal(1);
					noteRecord.setAbnormalInfo(warning.getCautionInfo());
					return;
				}
			}
			// 如果用户手帐备注包含异常信息，则提示警示内容
			if (StringUtils.isNotBlank(noteRecord.getRemark())) {
				if (noteRecord.getRemark().contains(warning.getRemark())) {
					noteRecord.setAbnormal(1);
					noteRecord.setAbnormalInfo(warning.getCautionInfo());
					return;
				}
			}
		}
		if (warning.getUpperBound() != null || warning.getLowerBound() != null) {
			// 如果用户手帐记录超过上下限，则提示警示内容
			// 记录大于上限
			if (new BigDecimal(warning.getUpperBound()).compareTo(noteRecord.getAmount()) == 1) {
				String warningInfo = warning.getCautionInfo();
				noteRecord.setAbnormal(1);
				noteRecord.setAbnormalInfo(warningInfo.replaceFirst("\\?", "高").replaceFirst("\\?", "超出")
						.replaceFirst("\\?", warning.getUpperBound().toString()));
			}
			// 记录小于下限
			if (new BigDecimal(warning.getLowerBound()).compareTo(noteRecord.getAmount()) == -1) {
				String warningInfo = warning.getCautionInfo();
				noteRecord.setAbnormal(1);
				noteRecord.setAbnormalInfo(warningInfo.replaceFirst("\\?", "低").replaceFirst("\\?", "低于")
						.replaceFirst("\\?", warning.getLowerBound().toString()));
			}
		}
	}

	public void createRecord() {
		NoteRecord noteRecord = getBean(NoteRecord.class, "");
		ApiResponse response = new ApiResponse();
		if (noteRecord.getNoteId() == null || noteRecord.getProjectId() == null || noteRecord.getAmount() == null
				|| noteRecord.getCreateTime() == null) {
			response.setStatusCode("4003");
			renderJson(response);
			return;
		}

		// 设置异常信息
		setAbnormal(noteRecord);

		noteRecord.setUpdateTime(new Date()).save();
		if (noteRecord.getRemark() != null && StringUtils.isNotBlank(noteRecord.getRemark())) { // 保存用户输入备注
			// 查检用户是否有该备注信息
			NoteTags noteTags = NoteTags.dao.findFirst(
					"select * from note_tags where note_id = ? and project_id = ? and remark = ? and view = 3",
					noteRecord.getNoteId(), noteRecord.getProjectId(), noteRecord.getRemark());
			if (noteTags != null) {
				noteTags.setHit(noteTags.getHit() + 1).setUpdateTime(new Date()).update();
			} else {
				new NoteTags().setNoteId(noteRecord.getNoteId()).setProjectId(noteRecord.getProjectId())
						.setRemark(noteRecord.getRemark()).setView(3).setHit(1).setCreateTime(new Date()).save();
			}
		}
		response.setData(noteRecord.getId());
		response.setStatusCode("0000");
		renderJson(response);
	}

	public void getRecordList() {
		Integer pageIndex = getParaToInt("pageIndex");
		if (pageIndex == null || pageIndex < 1) {
			pageIndex = 1;
		}
		Integer pageSize = getParaToInt("pageSize");
		if (pageSize == null) {
			pageSize = PAGESIZE;
		}
		long noteId = getParaToLong("noteId");
		long userId = getAttr(Constants.LOGIN_USER_ID);

		// 分页查找最近手帐记录
		Page<Record> records = Db.paginate(pageIndex, pageSize, "select * ",
				"from (" + "select nr.id,p.id projectId,n.id nid,p.project_type,p.project_name,p.project_icon,nr.create_time,nr.remark,nr.amount,nr.unit,"
						+ "nr.pic1,nr.pic2,nr.pic3,nr.pic4,nr.pic5,nr.pic6 "
						+ "from note_record nr left join project p on nr.project_id = p.id left join note n on nr.note_id = n.id "
						+ "where nr.note_id = ? and n.user_id = ? union all "
						+ "select nr.id,p.id projectId,n.id nid,p.project_type,p.project_name,p.project_icon,nr.create_time,nr.remark,nr.amount,nr.unit,"
						+ "nr.pic1,nr.pic2,nr.pic3,nr.pic4,nr.pic5,nr.pic6 "
						+ "from note_record nr left join project p on nr.project_id = p.id left join note n on nr.note_id = n.id "
						+ "left join note_share ns on nr.note_id = ns.note_id "
						+ "where ns.note_id = ? and ns.share_user_id = ? and ns.accept = 1) as r "
						+ "order by r.create_time desc",
				noteId, userId, noteId, userId);

		// 查找该手帐中所有宠物id
		List<Record> petIdsRecord = Db.find("select pet_id from pet_note where note_id = ?", noteId);
		List<Long> petIds = new ArrayList<Long>();
		for (Record record : petIdsRecord) {
			petIds.add(record.getLong("pet_id"));
		}
		// 查找该手帐所有宠物的宠物类别
		StringBuffer sql = new StringBuffer("select pet_category_id from pet where id in (");
		for (Long petId : petIds) {
			sql.append(petId).append(",");
		}
		String query = sql.substring(0, sql.length() - 1);
		query += ")";
		List<Record> petCategoryRecord = Db.find(query);
		Set<Long> petCategoryIds = new HashSet<Long>();
		for (Record record : petCategoryRecord) {
			petCategoryIds.add(record.getLong("pet_category_id"));
		}
		// 查找该手帐所有宠物父类类别
		sql = new StringBuffer("select parent_id from pet_category where id in (");
		for (Long petCategoryId : petCategoryIds) {
			sql.append(petCategoryId).append(",");
		}
		query = sql.substring(0, sql.length() - 1);
		query += ")";
		List<Record> petParentCategoryRecord = Db.find(query);
		for (Record record : petParentCategoryRecord) {
			petCategoryIds.add(record.getLong("parent_id"));
		}
		// 查找该手帐所有宠物类别
		sql = new StringBuffer("select * from pet_category where id in (");
		for (Long petCategoryId : petCategoryIds) {
			sql.append(petCategoryId).append(",");
		}
		query = sql.substring(0, sql.length() - 1);
		query += ")";
		List<PetCategory> petCategories = PetCategory.dao.find(query);

		List<RecordDetails> dailyRecords = new ArrayList<RecordDetails>();// 存放每天的手帐

		// 循环遍历设置要显示的值
		for (Record record : records.getList()) {
			RecordDetails recordDetails = new RecordDetails(record);

			// 查找异常警示
			List<Warning> warnings = Warning.dao.find(
					"SELECT * FROM warning WHERE project_id = ? OR project_id IS NULL", recordDetails.getProjectId());
			if (warnings != null) {
				for (Warning warning : warnings) {
					// 判断异常警示信息是否区分宠物类型
					if (warning.getPetCategoryId() == null) {
						setWarningInfo(warning, recordDetails);
					} else { // 区分宠物类别，判断是否与当前宠物是同类别，或当前异常警示信息作用于父节点
						// 判断警示信息宠物类别是否包含手帐宠物类别
						if (petCategories != null) {
							for (PetCategory petCategory : petCategories) {
								// 如果类别相同，则判断是备注信息是否包含异常信息
								if (petCategory.getId().equals(warning.getPetCategoryId())
										|| petCategory.getParentId().equals(warning.getPetCategoryId())) {
									setWarningInfo(warning, recordDetails);
								}
							}
						}
					}
				}
			}
			dailyRecords.add(recordDetails); // 存储当前记录
		}
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("dailyRecords", dailyRecords);
		resultMap.put("hasMore", records.isLastPage() ? "false" : "true");
		ApiResponse response = new ApiResponse();
		response.setData(resultMap);
		response.setStatusCode("0000");
		renderJson(JSON.toJSONString(response, SerializerFeature.WriteDateUseDateFormat));
	}

	public void getRecordByDay() {
		long noteId = getParaToLong("noteId");
		Date day = getParaToDate("day");
		long userId = getAttr(Constants.LOGIN_USER_ID);

		// 查找该日手帐
		List<Record> records = Db
				.find("select * from (select nr.id,p.id projectId,n.id nid,p.project_type,p.project_name,p.project_icon,nr.create_time,nr.remark,nr.amount,nr.unit,"
						+ "nr.pic1,nr.pic2,nr.pic3,nr.pic4,nr.pic5,nr.pic6 "
						+ "from note_record nr left join project p on nr.project_id = p.id left join note n on nr.note_id = n.id "
						+ "where nr.note_id = ? and n.user_id = ? and date(nr.create_time) = ? union all "
						+ "select nr.id,p.id projectId,n.id nid,p.project_type,p.project_name,p.project_icon,nr.create_time,nr.remark,nr.amount,nr.unit,"
						+ "nr.pic1,nr.pic2,nr.pic3,nr.pic4,nr.pic5,nr.pic6 "
						+ "from note_record nr left join project p on nr.project_id = p.id left join note n on nr.note_id = n.id "
						+ "left join note_share ns on nr.note_id = ns.note_id "
						+ "where ns.note_id = ? and ns.share_user_id = ? and ns.accept = 1 and date(nr.create_time) = ?) as r "
						+ "order by r.create_time", noteId, userId, day, noteId, userId, day);

		// 查找该手帐中所有宠物id
		List<Record> petIdsRecord = Db.find("select pet_id from pet_note where note_id = ?", noteId);
		List<Long> petIds = new ArrayList<Long>();
		for (Record record : petIdsRecord) {
			petIds.add(record.getLong("pet_id"));
		}
		// 查找该手帐所有宠物的宠物类别
		StringBuffer sql = new StringBuffer("select pet_category_id from pet where id in (");
		for (Long petId : petIds) {
			sql.append(petId).append(",");
		}
		String query = sql.substring(0, sql.length() - 1);
		query += ")";
		List<Record> petCategoryRecord = Db.find(query);
		Set<Long> petCategoryIds = new HashSet<Long>();
		for (Record record : petCategoryRecord) {
			petCategoryIds.add(record.getLong("pet_category_id"));
		}
		// 查找该手帐所有宠物父类类别
		sql = new StringBuffer("select parent_id from pet_category where id in (");
		for (Long petCategoryId : petCategoryIds) {
			sql.append(petCategoryId).append(",");
		}
		query = sql.substring(0, sql.length() - 1);
		query += ")";
		List<Record> petParentCategoryRecord = Db.find(query);
		for (Record record : petParentCategoryRecord) {
			petCategoryIds.add(record.getLong("parent_id"));
		}
		// 查找该手帐所有宠物类别
		sql = new StringBuffer("select * from pet_category where id in (");
		for (Long petCategoryId : petCategoryIds) {
			sql.append(petCategoryId).append(",");
		}
		query = sql.substring(0, sql.length() - 1);
		query += ")";
		List<PetCategory> petCategories = PetCategory.dao.find(query);

		List<RecordDetails> dailyRecords = new ArrayList<RecordDetails>();// 存放每天的手帐

		// 循环遍历设置要显示的值
		for (Record record : records) {
			RecordDetails recordDetails = new RecordDetails(record);

			// 查找异常警示
			List<Warning> warnings = Warning.dao.find(
					"SELECT * FROM warning WHERE project_id = ? OR project_id IS NULL", recordDetails.getProjectId());
			if (warnings != null) {
				for (Warning warning : warnings) {
					// 判断异常警示信息是否区分宠物类型
					if (warning.getPetCategoryId() == null) {
						setWarningInfo(warning, recordDetails);
					} else { // 区分宠物类别，判断是否与当前宠物是同类别，或当前异常警示信息作用于父节点
						// 判断警示信息宠物类别是否包含手帐宠物类别
						if (petCategories != null) {
							for (PetCategory petCategory : petCategories) {
								// 如果类别相同，则判断是备注信息是否包含异常信息
								if (petCategory.getId().equals(warning.getPetCategoryId())
										|| petCategory.getParentId().equals(warning.getPetCategoryId())) {
									setWarningInfo(warning, recordDetails);
								}
							}
						}
					}
				}
			}
			dailyRecords.add(recordDetails); // 存储当前记录
		}
		ApiResponse response = new ApiResponse();
		response.setData(dailyRecords);
		response.setStatusCode("0000");
		renderJson(response);
	}

	private void setWarningInfo(Warning warning, RecordDetails recordDetails) {
		// 判断异常警示是备注警示还是上下限警示
		if (StringUtils.isNotBlank(warning.getRemark())) {
			if (NumberUtils.isNumber(warning.getRemark())) { // 如果异常警示为数字，则判断用户手帐记录数量与异常数量是否相等，相等则异常
				double remark = NumberUtils.toDouble(warning.getRemark());
				if (recordDetails.getAmount().compareTo(new BigDecimal(remark)) == 0) {
					recordDetails.setCautionInfo(warning.getCautionInfo());
					return;
				}
			}
			// 如果用户手帐备注包含异常信息，则提示警示内容
			if (StringUtils.isNotBlank(recordDetails.getRemark())) {
				if (recordDetails.getRemark().contains(warning.getRemark())) {
					recordDetails.setCautionInfo(warning.getCautionInfo());
					return;
				}
			}
		}
		if (warning.getUpperBound() != null || warning.getLowerBound() != null) {
			// 如果用户手帐记录超过上下限，则提示警示内容
			// 记录大于上限
			if (recordDetails.getAmount().compareTo(new BigDecimal(warning.getUpperBound())) == 1) {
				String warningInfo = warning.getCautionInfo();
				recordDetails.setCautionInfo(warningInfo.replaceFirst("\\?", "高").replaceFirst("\\?", "超出")
						.replaceFirst("\\?", warning.getUpperBound().toString()));
			}
			// 记录小于下限
			if (recordDetails.getAmount().compareTo(new BigDecimal(warning.getLowerBound())) == -1) {
				String warningInfo = warning.getCautionInfo();
				recordDetails.setCautionInfo(warningInfo.replaceFirst("\\?", "低").replaceFirst("\\?", "低于")
						.replaceFirst("\\?", warning.getLowerBound().toString()));
			}
		}
	}

	public void delPic() {
		long recordId = getParaToLong("recordId");
		String picIndex = getPara("picIndex");
		long userId = getAttr(Constants.LOGIN_USER_ID);
		ApiResponse response = new ApiResponse();
		// 判断该手帐是否为该用户手帐
		NoteRecord record = RecordService.recordBelong(recordId, userId);
		if (record != null) {
			record.set(picIndex, null).update();
			response.setData("success");
			response.setStatusCode("0000");
			renderJson(response);
			return;
		}
		response.setData("failed");
		response.setStatusCode("4001");
		renderJson(response);
	}

	public void delRecord() {
		long recordId = getParaToLong("recordId");
		long userId = getAttr(Constants.LOGIN_USER_ID);
		ApiResponse response = new ApiResponse();
		// 判断该手帐是否为该用户手帐
		NoteRecord record = RecordService.recordBelong(recordId, userId);
		if (record != null) {
			record.delete();
			response.setData("success");
			response.setStatusCode("0000");
			renderJson(response);
			return;
		}
		response.setData("failed");
		response.setStatusCode("4001");
		renderJson(response);
	}

	public void updateRecord() {
		NoteRecord recordPara = getBean(NoteRecord.class, "");
		long userId = getAttr(Constants.LOGIN_USER_ID);
		ApiResponse response = new ApiResponse();
		// 判断该手帐是否为该用户手帐
		NoteRecord record = RecordService.recordBelong(recordPara.getId(), userId);
		if (record != null) {
			if (recordPara.getRemark() != null && StringUtils.isNotBlank(recordPara.getRemark())) { // 保存用户输入备注
				// 查检用户是否有该备注信息
				NoteTags noteTags = NoteTags.dao.findFirst(
						"select * from note_tags where note_id = ? and project_id = ? and remark = ? and view = 3",
						record.getNoteId(), record.getProjectId(), recordPara.getRemark());
				if (noteTags != null) {
					noteTags.setHit(noteTags.getHit() + 1).setUpdateTime(new Date()).update();
				} else {
					new NoteTags().setNoteId(recordPara.getNoteId()).setProjectId(record.getProjectId())
							.setRemark(recordPara.getRemark()).setView(3).setHit(1).setCreateTime(new Date()).save();
				}
			}

			recordPara.setProjectId(record.getProjectId());
			recordPara.setNoteId(record.getNoteId());
			if (recordPara.getAmount() == null) {
				recordPara.setAmount(record.getAmount());
			}
			// 设置异常信息
			setAbnormal(recordPara);

			recordPara.update();
			response.setData(recordPara);
			response.setStatusCode("0000");
			renderJson(response);
			return;
		}
		response.setData("failed");
		response.setStatusCode("4001");
		renderJson(response);
	}

	public void getRecordsChart() {
		String[] projects = getParaValues("projects");
		String[] remarks = getParaValues("remarks");
		long noteId = getParaToLong("noteId");
		Date startTime = getParaToDate("startTime");
		Date endTime = getParaToDate("endTime");
		int view = getParaToInt("view");
		long userId = getAttr(Constants.LOGIN_USER_ID);
		ApiResponse response = new ApiResponse();
		if (projects == null || projects.length < 1 || startTime == null || endTime == null
				|| startTime.getTime() > endTime.getTime()) {
			response.setData("参数错误");
			response.setStatusCode("0003");
			renderJson(response);
			return;
		}
		List<RecordList> result = new ArrayList<RecordList>();
		for (int i = 0; i < projects.length; i++) {
			long projectId = Long.valueOf(projects[i]);
			String projectRemark = null;
			if (remarks != null && remarks.length > i && StringUtils.isNotBlank(remarks[i])) {
				projectRemark = remarks[i];
			}

			// 查找是否有该常用列表项
			NoteTags noteTags;
			if (projectRemark == null) {
				noteTags = NoteTags.dao.findFirst(
						"select * from note_tags where note_id = ? and project_id = ? and remark is null and view = ?",
						noteId, projectId, view);
			} else {
				noteTags = NoteTags.dao.findFirst(
						"select * from note_tags where note_id = ? and project_id = ? and remark = ? and view = ?",
						noteId, projectId, projectRemark, view);
			}
			// 如果存在该常用列表项，则更新hit和更新日期
			if (noteTags != null) {
				noteTags.setHit(noteTags.getHit() + 1).setUpdateTime(new Date()).update();
			} else { // 不存在该常用列表项，新建常用列表项
				new NoteTags().setNoteId(noteId).setProjectId(projectId).setRemark(projectRemark).setView(view)
						.setHit(1).setCreateTime(new Date()).save();
			}

			List<Object> params = new ArrayList<Object>();
			params.add(userId);
			params.add(startTime);
			params.add(endTime);
			params.add(projectId);
			params.add(noteId);
			params.add(userId);
			params.add(startTime);
			params.add(endTime);
			params.add(projectId);
			params.add(noteId);
			RecordList recordList = new RecordList();
			if (projectRemark != null) {
				recordList.setRemark(projectRemark);
				projectRemark = "%" + projectRemark + "%";
				params.add(projectRemark);
			}

			StringBuffer sql = new StringBuffer();
			sql.append(
					"select nr.*,p.project_name from note_record nr join note n on nr.note_id = n.id join project p on nr.project_id = p.id "
							+ "where n.user_id = ? and date(nr.create_time) between ? and ? and nr.project_id = ? and nr.note_id = ? union all "
							+ "select nr.*,p.project_name from note_share ns left join note_record nr on ns.note_id = nr.note_id "
							+ "left join note n on nr.note_id = n.id left join project p on nr.project_id = p.id "
							+ "where ns.share_user_id = ? and date(nr.create_time) between ? and ? and nr.project_id = ? and nr.note_id = ? and ns.accept = 1");
			if (projectRemark != null) {
				sql.append(" and remark like ?");
			}
			sql.append(" order by create_time");
			List<NoteRecord> noteRecords = NoteRecord.dao.find(sql.toString(), params.toArray());
			if (noteRecords != null && noteRecords.size() > 0) {
				NoteRecord record = noteRecords.get(0);
				recordList.setProjectName(record.get("project_name"));
			}
			recordList.setRecordList(noteRecords);
			result.add(recordList);
		}
		response.setData(result);
		response.setStatusCode("0000");
		renderJson(JSON.toJSONString(response, SerializerFeature.WriteDateUseDateFormat));
	}

	public void getMonthData() {
		long noteId = getParaToLong("noteId");
		int year = getParaToInt("year");
		int month = getParaToInt("month");
		long userId = getAttr(Constants.LOGIN_USER_ID);
		Calendar calendar = Calendar.getInstance();
		calendar.set(year, month - 1, 1);
		Date startDate = calendar.getTime();
		int day = calendar.getActualMaximum(Calendar.DATE);
		calendar.set(year, month - 1, day);
		Date endDate = calendar.getTime();
		List<Record> records = Db.find(
				"select date(nr.create_time) date from note_record nr join note n on nr.note_id = n.id "
						+ "where n.user_id = ? and nr.note_id = ? and date(nr.create_time) between date(?) and date(?) group by date(nr.create_time)",
				userId, noteId, startDate, endDate);
		ApiResponse response = new ApiResponse();
		response.setData(records);
		response.setStatusCode("0000");
		renderJson(response);
	}

	public void getAbnormal() {
		long noteId = getParaToLong("noteId");
		int tops = getParaToInt("tops");
		Page<Record> records = Db.paginate(1, tops, "select * ",
				"from (" + "select n.*,p.`project_name`,p.`project_icon` FROM note_record n LEFT JOIN project p ON n.`project_id` = p.`id` "
						+ "where n.note_id = ? and n.abnormal = 1 order by n.create_time desc) as r",
				noteId);
		List<RecordDetails> dailyRecords = new ArrayList<RecordDetails>();
		for (Record record : records.getList()) {
			RecordDetails recordDetails = new RecordDetails(record);
			recordDetails.setCautionInfo(record.getStr("abnormal_info"));
			dailyRecords.add(recordDetails);
		}
		ApiResponse response = new ApiResponse();
		response.setData(dailyRecords);
		response.setStatusCode("0000");
		renderJson(response);
	}
}
